package com.youlu.campus.admin.data.controller;

import com.youlu.campus.admin.data.dto.DataOverviewQueryRequest;
import com.youlu.campus.admin.data.service.DayAnalysisService;
import com.youlu.campus.admin.data.service.DayDataStatisticsService;
import com.youlu.campus.admin.utils.AuthUtils;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * 数据统计
 */
@RestController
@RequestMapping("/data")
public class DataStatisticsController {
    @Autowired
    private DayDataStatisticsService dayDataStatisticsService;
    @Autowired
    private DayAnalysisService dayAnalysisService;

    /**
     * 日打卡概览
     * @param request 日打卡概览请求类
     * @return
     */
    @PostMapping("/day/check-in/overview")
    public QResult dayCheckInOverview(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getDayCheckInStatisticsOverview(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 日社区概览
     * @param request 日社区请求类
     * @return
     */
    @PostMapping("/day/community/overview")
    public QResult dayCommunityOverview(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getDayCommunityStatisticOverview(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 日小组组长概览
     * @param request 日打卡概览请求类
     * @return
     */
    @PostMapping("/day/group-leaders/overview")
    public QResult dayGroupLeadersOverview(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getDayGroupLeaderStatisticsOverview(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 日小组概览
     * @param request 日小组概览请求类
     * @return
     */
    @PostMapping("/day/group/overview")
    public QResult dayGroupOverview(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getDayGroupStatisticsOverview(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 日小组成员概览
     * @param request 日小组成员概览请求类
     * @return
     */
    @PostMapping("/day/member-group/overview")
    public QResult dayMemberGroupOverview(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getDayMemberGroupStatisticsOverview(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 日用户概览
     * @param request 日打卡概览请求类
     * @return
     */
    @PostMapping("/day/day-users/overview")
    public QResult dayUsersOverview(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getDayUserStatisticsOverview(tenantId, request.getStartTime(), request.getEndTime()));
    }


    /**
     * 打卡数据历史
     * @param request 打卡概览请求类
     * @return
     */
    @PostMapping("/history/check-in")
    public QResult checkInHistory(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getCheckInStatisticsHistory(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 社区历史
     * @param request 社区请求类
     * @return
     */
    @PostMapping("/history/community")
    public QResult communityHistory(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getCommunityStatisticHistory(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 小组组长历史
     * @param request 日打卡概览请求类
     * @return
     */
    @PostMapping("/history/group-leaders")
    public QResult groupLeadersHistory(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getGroupLeaderStatisticsHistory(tenantId, request.getStartTime(), request.getEndTime()));
    }


    /**
     * 小组历史
     * @param request 日小组概览请求类
     * @return
     */
    @PostMapping("/history/group")
    public QResult groupHistory(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getGroupStatisticsHistory(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 小组成员历史
     * @param request 小组成员历史请求类
     * @return
     */
    @PostMapping("/history/member-group")
    public QResult memberGroupHistory(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getMemberGroupStatisticsHistory(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 日用户数据历史
     * @param request 日用户数据历史请求类
     * @return
     */
    @PostMapping("/history/day-users")
    public QResult usersHistory(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayDataStatisticsService.getUserStatisticsHistory(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 裂变数据分析
     * @param request 裂变数据分析请求类
     * @return
     */
    @PostMapping("/fission/analysis")
    public QResult fissionData(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayAnalysisService.getDayFissionStatistics(tenantId, request.getStartTime(), request.getEndTime()));
    }

    /**
     * 转化数据分析
     * @param request 转化数据分析请求类
     * @return
     */
    @PostMapping("/conversion/analysis")
    public QResult conversionData(@RequestBody @NotNull DataOverviewQueryRequest request) {
        String tenantId = AuthUtils.getComId();
        return QResult.success(dayAnalysisService.getDayConversionStatistics(tenantId, request.getStartTime(), request.getEndTime()));
    }
}